package fctuc.dei.myTwitter.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import fctuc.dei.myTwitter.constants.MyTwitterConstants;

public class DbTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Statement stmt;
		Connection con;
		ResultSet rs;
		String username  = "marco";
		String password = "marco";
		int id = 32;
		try {
			//Register de JDBC driver for MySQL
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			
			//Connect
			con = DriverManager.getConnection(
												MyTwitterConstants.DB_URL,
												MyTwitterConstants.DB_USERNAME,
												MyTwitterConstants.DB_PASSWORD
												);
			

			//Get a Statement object
			stmt = con.createStatement();
			
			try{
				if(!con.isClosed())
					stmt.executeQuery("SELECT * FROM USERS WHERE USER_ID = " + id);// = \""+username+"\" AND USER_PASSWORD = \""+password+"\"");
				rs = stmt.getResultSet();
				System.out.println("teste");
				while(rs.next())
					System.out.println((String)rs.getObject(2));
			}
			catch (SQLException ex){
				while (ex != null){
					System.out.println("SQL Exception: " + ex.getMessage());
					ex = ex.getNextException();
				}
			}
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
